package multiThreading;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class B {
    public static void main(String arg[]){
        //模拟线程池的操作
        ExecutorService pool= Executors.newFixedThreadPool(14);//开辟一个空间为14的线程池
        List<String>list=new ArrayList<>();
        for(int i=0;i<10;i++){
            b1 b=new b1("A"+i);//起名字
            Future<String> f=pool.submit(b);
            try {
                list.add(f.get());//放到集合中
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
        pool.shutdown();//关闭线程池
        //遍历线程池中的结果
        System.out.println("线程池中有："+list );
    }
}

class b1 implements Callable<String> {//Callable可以使用相对应的泛型来控制返回值类型
    private static String name;
    @Override
    public String call() throws Exception {
        return this.name;
    }
    public b1(String name){
        this.name=name;
    }
}